//
//  selectCarmaerVi.m
//  YuanyangJinlou
//
//  Created by mac004 on 2017/1/6.
//  Copyright © 2017年 suli19910309@qq.com. All rights reserved.
//

#import "CarmaerView.h"

@implementation CarmaerView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(instancetype)initWithFrame:(CGRect)frame{
    if (self =[super initWithFrame:frame]) {
        [self creatUI];
    }
    return self;
}
-(void)creatUI{
    UIView * bgView=[[UIView alloc]initWithFrame:CGRectMake(12*PER_WIDTH, 0, SCREEN_WIDTH-24*PER_WIDTH, 160*PER_HEIGHT)];
    bgView.layer.cornerRadius=10;
    bgView.layer.masksToBounds=YES;
    bgView.backgroundColor=[UIColor whiteColor];
    [self addSubview:bgView];
    NSArray * titleArr=@[@"拍照",@"从手机相册选择"];
    
    UIImage * img =[UIImage imageNamed:@"ico_biaoqian"];
    UIImageView * imgView=[[UIImageView alloc]initWithFrame:CGRectMake(bgView.width/2-img.size.width*PER_WIDTH/2, 0, img.size.width*PER_WIDTH, img.size.height*PER_HEIGHT)];
    imgView.image=img;
    [bgView addSubview:imgView];
    UILabel* lab =[MyControl createLabelWithFrame:CGRectMake(0, 0, imgView.width, imgView.height) Font:15 Text:@"请选择照片" Color:WHITE_COLOR];
    lab.textAlignment=NSTextAlignmentCenter;
    [imgView addSubview:lab];
    
    for (int i = 0 ; i<2; i++) {
        UIButton*btn=[UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame=CGRectMake(0, 60*PER_HEIGHT+i*50*PER_HEIGHT, bgView.width, 50*PER_WIDTH);
        btn.tag=100+i;
        [btn addTarget:self action:@selector(btn:) forControlEvents:UIControlEventTouchUpInside];
        [bgView addSubview:btn];
        UIView * line =[[UIView alloc]initWithFrame:CGRectMake(0, 60*PER_HEIGHT+i*50*PER_HEIGHT, bgView.width, 0.5)];
        line.backgroundColor=UIColorFromHex(0xcccccc);
        [bgView addSubview:line];
        
        UILabel * lab=[MyControl createLabelWithFrame:CGRectMake(0, 60*PER_HEIGHT+i*50*PER_HEIGHT, bgView.width, 50*PER_HEIGHT) Font:15 Text:titleArr[i] Color:TINK_COLOR];
        lab.textAlignment=NSTextAlignmentCenter;
        [bgView addSubview:lab];
    }
    
    UIButton * cancel =[UIButton buttonWithType:UIButtonTypeCustom];
    cancel .frame=CGRectMake(bgView.left, bgView.bottom+10*PER_HEIGHT, bgView.width, 50*PER_HEIGHT);
    cancel.layer.cornerRadius=10;
    cancel.layer.masksToBounds=YES;
    cancel.backgroundColor=[UIColor whiteColor];
    [cancel setTitle:@"取消" forState:0];
    [cancel setTitleColor:TINK_COLOR forState:0];
    cancel.titleLabel.font=[UIFont fontWithName:HSGBW3 size:15*PER_HEIGHT];
    cancel.titleLabel.font=[UIFont systemFontOfSize:15*PER_HEIGHT];
    [cancel addTarget:self action:@selector(cancelBtn) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:cancel];
    
}
-(void)btn:(UIButton*)sender{
    if (sender.tag==100) {
        if (_delege&&[_delege respondsToSelector:@selector(chooseCarmer)]) {
            [_delege chooseCarmer];
        }
    }else{
        if (_delege&&[_delege respondsToSelector:@selector(choosePhoto)]) {
            [_delege choosePhoto];
        }

    }
}
-(void)cancelBtn{
    if (_delege&&[_delege respondsToSelector:@selector(cancel)]) {
        [_delege cancel];
    }

}
@end
